# ======================================================================================
# File         : c.snippets
# Author       : Wu Jie 
# Last Change  : 06/16/2009 | 13:36:28 PM | Tuesday,June
# Description  : 
# ======================================================================================

# ------------------------------------------------------------------ 
# Desc: main()
# ------------------------------------------------------------------ 

snippet main
	int main( int argc, char* argv[] )
	{
		${1:/* TODO: code */}
		return 0;
	}

# ------------------------------------------------------------------ 
# Desc: #include "..."
# ------------------------------------------------------------------ 

snippet inc
	#include "${1:`Filename("$1.h")`}"${2}

# ------------------------------------------------------------------ 
# Desc: #include <...>
# ------------------------------------------------------------------ 

snippet Inc
	#include <${1:stdio}.h>${2}

# ------------------------------------------------------------------ 
# Desc: 
# #ifndef ... 
# #define ... 
# #endif
# ------------------------------------------------------------------ 

snippet Def
	#ifndef $1
		#define ${1:SYMBOL} ${2:value}
	#endif${3}

# ------------------------------------------------------------------ 
# Desc: #define 
# ------------------------------------------------------------------ 

snippet def
	#define 

# ------------------------------------------------------------------ 
# Desc: Header Include-Guard
# (the randomizer code is taken directly from TextMate; it could probably be
# cleaner, I don't know how to do it in vim script)
# ------------------------------------------------------------------ 

snippet guard
	// #################################################################################
	#ifndef ${1:`toupper( fnamemodify(bufname('%'), ':t:r') .'_'. fnamemodify(bufname('%'), ':e') .'_'. localtime() )`}
	#define $1
	// #################################################################################

	${2:/* TODO: code */}

	// #################################################################################
	#endif // END $1
	// #################################################################################

# ------------------------------------------------------------------ 
# Desc: #pragma once 
# ------------------------------------------------------------------ 

snippet once
	#pragma once

# ------------------------------------------------------------------ 
# Desc: If Condition
# ------------------------------------------------------------------ 

snippet if
	if ( ${1:/* TODO: condition */} ) 
	{
		${2:/* TODO: code */}
	}
snippet elif
	else if ( ${1:/* TODO: condition */} ) 
	{
		${2:/* TODO: code */}
	}
snippet el
	else 
	{
		${1:/* TODO: code */}
	}

# ------------------------------------------------------------------ 
# Desc: Tertiary conditional
# ------------------------------------------------------------------ 

snippet t
	${1:/* TODO: condition */} ? ${2:a} : ${3:b}

# ------------------------------------------------------------------ 
# Desc: Do While Loop
# ------------------------------------------------------------------ 

snippet do
	do {
		${2:/* TODO: code */}
	} while ( ${1:/* TODO: condition */} );

# ------------------------------------------------------------------ 
# Desc: While Loop
# ------------------------------------------------------------------ 

snippet wh
	while ( ${1:/* TODO: condition */} ) 
	{
		${2:/* TODO: code */}
	}

# ------------------------------------------------------------------ 
# Desc: For Loop
# ------------------------------------------------------------------ 

snippet for
	for ( int ${1:i} = 0; $1 < ${2:count}; ++$1 )
	{
		${3:/* TODO: code */}
	}

# ------------------------------------------------------------------ 
# Desc: Iterator For Loop
# ------------------------------------------------------------------ 

snippet fori
	for ( ${1:iterator} ${2:iter} = ${3:container}.Begin(); $2 != $3.End(); ++$2 )
	{
		${4:/* TODO: code */}
	}

# ------------------------------------------------------------------ 
# Desc: Custom For Loop
# ------------------------------------------------------------------ 

snippet forc
	for ( ${1:int} ${2:i} = ${3:0}; $2 ${4:< count}; ${5:++}$2 ) 
	{
		${6:/* TODO: code */}
	}

# ------------------------------------------------------------------ 
# Desc: Function
# ------------------------------------------------------------------ 

snippet fn
	${1:void} ${2:function_name} (${3})
	{
		${4:/* TODO: code */}
	}

# ------------------------------------------------------------------ 
# Desc: Typedef
# ------------------------------------------------------------------ 

snippet td
	typedef ${1:type_name} ${2:type_name_t};

# ------------------------------------------------------------------ 
# Desc: Typedef struct
# ------------------------------------------------------------------ 

snippet tds
	typedef struct ${1:name} 
	{
		${3:/* TODO: members */}
	} ${2:$1_t};

# ------------------------------------------------------------------ 
# Desc: Struct
# ------------------------------------------------------------------ 

snippet st
	///////////////////////////////////////////////////////////////////////////////
	// struct $1
	// 
	// Purpose: 
	// 
	///////////////////////////////////////////////////////////////////////////////

	struct ${1:name} 
	{
		${2:/* TODO: members */}
	}; // end struct $1

# ------------------------------------------------------------------ 
# Desc: printf
# unfortunately version this isn't as nice as TextMates's, given the lack of a dynamic `...`
# ------------------------------------------------------------------ 

snippet pr
	printf ( "${1:%s}\n", ${2} );

# ------------------------------------------------------------------ 
# Desc: fprintf (again, this isn't as nice as TextMate's version, but it works)
# ------------------------------------------------------------------ 

snippet fpr
	fprintf ( ${1:stderr}, "${2:%s}\n", ${3} );
